Learn how to identify users with pseudonymous user tokens for all click and conversion events.
setAuthenticatedUserToken
method to set the authenticated user token as the authenticatedUserToken
parameter for the Insights client.
getAuthenticatedUserTokenAfterLogin()
function.
It is important to set the authenticatedUserToken
parameter for authenticated users rather than userToken
, which is intended to be used for anonymous tokens.
If a user initially visits a site without signing in, they’re assigned an anonymous ID. If they later sign in and receive an authenticated user ID, setting the userToken
to the authenticated user ID would overwrite the anonymous ID, meaning their previous activity as an anonymous user won’t be associated with the authenticated user.
By sending the anonymous and authenticated user tokens in separate parameters, you can ensure continuity of user activity and prevent data loss during the transition from
anonymous to authenticated status.
If you’re not using user authentication, use a cookie to persist the anonymous user token in the userToken
parameter.
userToken
in a first-party cookie with the name _ALGOLIA
on the user’s device,
set the useCookie
parameter in the init
method to true
.
This lets you identify users across sessions with the persistent, anonymous user token.
useCookie
to true
, you should get user consent.
For example, you can dynamically update the useCookie
parameter when the user accepts non-essential cookies.
Use the ‘partialparameter to only update the
useCookie` option without changing the others.
useCookie
as false
and only update its value dynamically once the user grants or withdraws consent.
For example, your code could look like this:
_ALGOLIA
cookie expires after 6 months.
To adjust the lifespan of the cookie, set the cookieDuration
parameter.
_ga
.
If you’re already using Google Analytics on your website, you can use that user token as the Search Insights library’s userToken
parameter.
The value of the _ga
cookie follows the pattern GA1.1.1900000000.1684510679
and has three components:
GA1.1.
. Indicates the version of the Google Analytics tracking library used to generate the cookie.1900000000
. A unique identifier for distinguishing individual users.1684510679
. The timestamp when the cookie was created, in Unix epoch time.userToken
for Search Insights with setUserToken
.
ajs_anonymous_id
.
If you’re already using Segment on your website, you can use that user token as the Search Insights library’s userToken
parameter.
Using Segment’s Analytics.js 2.0 library,
you can get the user token from the function analytics.user().anonymousId()
.
getUserToken
.
getAuthenticatedUserToken
userToken
. You can also manually set the userToken
or authenticatedUserToken
parameter in two ways: either globally or for each event.
To set userToken
or authenticatedUserToken
globally, you can pass them on init
or use the setUserToken
or
setAuthenticatedUserToken
method. This way, you don’t need to provide your user token every time you send an event.
userToken
and authenticatedUserToken
parameters to the event object.
analytics
and enablePersonalization
to false
to turn off these features.